
import javafx.animation.TranslateTransition;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.*;
import javafx.scene.paint.Color;



public class Card extends ImageView{
	public int number;
	public int color;
	private String cardName;
	private int size=1;
	private float scaleFactor=0.15f;
	private boolean isTurnedBack;
	public boolean isSelected;
	
	public Card(){
		this.turnBack();
		isSelected = false;
	}
	
	public Card(Card cd){
		number = cd.number;
		color = cd.color;
		cardName = cd.cardName;
		isSelected = false;
		if(cd.isTurnedBack){
			this.turnBack();
		}
		else{
			this.turnUp();
		}
	}
	
	public Card(int num,int col){
		try{
			number = num;
			color = col;
			isSelected = false;
			if(col>=1 && col<=6){
				if(number<10 && number>=0){
					cardName = col +"0"+number+"_"+size+".jpg";
				}
				else if(number==10){
					cardName = col+"" + number + "_"+size +".jpg";
				}
				this.turnUp();

			}
			else{
				throw new Exception("Exception:wrong card");
			}
		
		}
		catch(Exception ex){
			System.out.println("wrong card");
		}
	}
	
	private void LoadImage(String name){
		Image img = new Image(name,600*scaleFactor,900*scaleFactor,true,true);
		this.setImage(img);	
		
		
		 DropShadow shadow = new DropShadow();
		 shadow.setOffsetX(0.4);
		 shadow.setOffsetY(0.4);
		 shadow.setColor(Color.BLACK.brighter());
	 	 this.setEffect(shadow);
	 	 
	 	
	}
	
	public void turnBack(){
		this.LoadImage("back_1.jpg");
		isTurnedBack=true;
	}
	
	public void turnUp(){
		System.out.println(cardName);

		this.LoadImage(cardName);
		isTurnedBack=false;
	}
	
	public boolean isTurnedBack(){
		return isTurnedBack;
	}
	
	//如果动的过快前一个动作还没完成就会变形
	public void Bigger(){
		this.isSelected=true;
		
		 DropShadow shadow = new DropShadow();
		 shadow.setOffsetX(0.4);
		 shadow.setOffsetY(0.4);
		 shadow.setColor(Color.RED.brighter());
	 	 this.setEffect(shadow);
	 	 
	 	TranslateTransition moveup = new TranslateTransition();
	 	moveup.setNode(this);
	 	moveup.setToY(-20);
	 	moveup.play();

	}
	
	public void Smaller(){
		this.isSelected=false;

		 DropShadow shadow = new DropShadow();
		 shadow.setOffsetX(0.4);
		 shadow.setOffsetY(0.4);
		 shadow.setColor(Color.BLACK.brighter());
	 	 this.setEffect(shadow);
	 	 
	 	TranslateTransition moveup = new TranslateTransition();
	 	moveup.setNode(this);
	 	moveup.setToY(0);
	 	moveup.play();
	}
	
	
	public void transparent(){
		this.setOpacity(0.5);
	}
	
	public void opacity(){
		this.setOpacity(1);

	}
	
}
